<?php
/**
 * Created by JetBrains PhpStorm.
 * User: dung
 * Date: 2/12/14
 * Time: 9:32 AM
 * To change this template use File | Settings | File Templates.
 */
?>

<?php
//Function User
function CheckUser($users,$password){
    $query="SELECT * FROM `dt_users` WHERE name='$users' and password='$password'";
    return mysql_query($query);
}

?>


<?php
//Function News
function AddNews($Title,$Summary,$Image,$datepicker,$IDUser,$language_id,$Content,$AnHien){
    $query="INSERT INTO  `dt_news` VALUES (NULL , '$IDUser', '$Title', '$Summary', '$Content', '$Image', '$datepicker', '$AnHien', '$language_id')";
    mysql_query ($query);
}

function CheckTitle($IDNews){
    $query="SELECT * FROM 'dt_news' WHERE new_id='$IDNews'";
    return mysql_query($query);
}

function NewsDetail($IDNews){
    $query="SELECT * FROM `dt_news` WHERE new_id=$IDNews";
    return mysql_query($query);

}

function EditNews($IDNews,$IDUser,$Title,$Summary,$Content,$Image,$datepicker,$AnHien,$language_id){
    $query="UPDATE `dt_news` SET
        `user_id`='$IDUser',
		`title`= '$Title',
		`summary` ='$Summary',
		`content` ='$Content',
		`image` ='$Image',
		`date_added` ='$datepicker',
		`hide/show`='$AnHien',
		`language_id`='$language_id'
		WHERE new_id=$IDNews";
    mysql_query ($query);
}

function DeleteNews($IDNews){
    $query="DELETE FROM `dt_news` WHERE new_id=$IDNews";
    mysql_query($query);
}

function CountNews(){
    $query="SELECT COUNT(new_id) FROM `dt_news`";
    return mysql_query($query);
}

function NewsLists($start){
    $query="SELECT * FROM `dt_news` ORDER BY `new_id` DESC LIMIT $start,10";
    return mysql_query($query);
}

?>


<?php
//Function Contacts
function ContactsInsert($name, $email, $contents, $date) {
    $query = "INSERT INTO `dt_contacts` VALUES (	NULL, '$name', '$email', '$contents', '$date')";
    mysql_query($query);
}

function ContactsList($start){
    $query="SELECT * FROM `dt_contacts` ORDER BY `date_added` DESC LIMIT $start,10";
    return mysql_query($query);
}

?>


<?php
//Link Function
function LinkList($start){
    $query="SELECT * FROM `dt_link` ORDER BY `linked_id` DESC LIMIT $start,10";
    return mysql_query($query);
}

function AddLink($Title,$Linked,$language_id,$AnHien){
    $query="INSERT INTO `dt_link` VALUES (NULL, '$Title', '$Linked', '$AnHien', '$language_id')";
    mysql_query($query);
}

function DeleteLink($id){
    $query="DELETE FROM `dt_link` WHERE linked_id=$id";
    mysql_query($query);
}

function LinkDetail($id){
    $query="SELECT * FROM `dt_link` WHERE linked_id=$id";
    return mysql_query($query);
}

function EditLink($id,$Title,$Linked,$language_id,$AnHien){
    $query="UPDATE `dt_link` SET
		`title`='$Title',
		`linked`='$Linked',
		`language_id`='$language_id',
		`hide/show`='$AnHien'
		WHERE link_id=$id";
    mysql_query ($query);
}

?>


<?php
//Employee Function
function EmployeeList($start){
    $query="SELECT * FROM `dt_employee` ORDER BY `linked_id` DESC LIMIT $start,10";
    return mysql_query($query);
}

function DeleteEmployee($id){
    $query="DELETE FROM `dt_employee` WHERE employee_id=$id";
    mysql_query($query);
}

function AddEmployee($name,$image,$detail,$language_id){
    $query="INSERT INTO `dt_employee` VALUES (NULL, '$name', '$image', '$detail', '$language_id')";
    mysql_query($query);
}

function EditEmployee($id,$name,$image,$detail,$language_id){
    $query="UPDATE `dt_employee` SET
		`name`='$name',
		`image`='$image',
		`detail`='$detail',
		`language_id`='$language_id'
		WHERE employee_id=$id";
    return mysql_query ($query);
}

function EmployeeDetail($id){
    $query="SELECT * FROM `dt_employee` WHERE employee_id=$id";
    return mysql_query($query);
}

?>


<?php
//Language Function
function LanguageList(){
    $query="SELECT * FROM `dt_language`";
    return mysql_query($query);
}
?>

<?php
//Recruitment Function
function RecruitmentList($start){
    $query="SELECT * FROM `dt_recruitment` ORDER BY `recruitment_id` DESC LIMIT $start,10";
    return mysql_query($query);
}

function RecruitmentDetail($id){
    $query="SELECT * FROM `dt_recruitment` WHERE employee_id=$id";
    return mysql_query($query);
}

function AddRecruitment($title,$content,$date_added,$AnHien,$language_id,$user_id){
    $query="INSERT INTO `dt_recruitment` VALUES (NULL, '$title', '$content', '$date_added', '$AnHien', '$language_id', '$user_id')";
    mysql_query($query);
}

function EditRecruitment($id,$title,$content,$date_added,$AnHien,$language_id,$user_id){
    $query="UPDATE `dt_recruitment` SET
		`title`='$title',
		`content`='$content',
		`date_added`='$date_added',
		`hide/show`='$AnHien',
		`language_id`='$language_id',
		`user_id`='$user_id'
		WHERE recruitment_id=$id";
    mysql_query($query);
}

function DeleteRecruitment($id){
    $query="DELETE FROM `dt_recruitment` WHERE recruitment_id=$id";
    mysql_query($query);
}

?>

<?php
//Function User
function UserList($start){
    $query="SELECT * FROM `dt_users` ORDER BY `user_id` DESC LIMIT $start,10";
    return mysql_query($query);
}

function AddUser($name,$password,$email,$group_id){
    $query="INSERT INTO `dt_users` VALUES (NULL,'$name','$password','$email','$group_id')";
    mysql_query($query);
}

function UserDetail($id){
    $query="SELECT * FROM `dt_users` WHERE user_id=$id";
    return mysql_query($query);
}

function EditUser($id,$name,$password,$email,$group_id){
    if(strlen($password)!=null){
        $query="UPDATE `dt_users` SET
		`name`= '$name',
		`password` ='$password',
		`email` ='$email',
		`group_id` ='$group_id'
		WHERE user_id=$id";
        mysql_query ($query);
    }else{
        $query="UPDATE `dt_users` SET
		`name`= '$name',
		`email` ='$email',
		`group_id` ='$group_id'
		WHERE user_id=$id";
        mysql_query ($query);
    }

}

function DeleteUser($id){
    $query="DELETE FROM `dt_users` WHERE user_id=$id";
    mysql_query($query);
}

function CheckUserName($name){
    $query="SELECT * FROM `dt_users` WHERE name=$name";
    return mysql_query($query);
}

?>

<?php
//Function Group User
function GroupDetail($id){
    $query="SELECT * FROM `dt_group` WHERE group_user_id=$id";
    return mysql_query($query);
}

function GroupList(){
    $query="SELECT * FROM `dt_group`";
    return mysql_query($query);
}

?>


<?php
//Function Information
function InformationList($start){
    $query="SELECT * FROM `dt_information` ORDER BY `information_id` DESC LIMIT $start,10";
    return mysql_query($query);
}

function AddInformation($name,$content,$language_id,$group){
    if($group=='home_page'){
        $query="DELETE FROM `dt_information` WHERE group=$group";
        mysql_query($query);
        $query="INSERT INTO `dt_information` VALUES (NULL,'$group','$name','$content','$language_id')";
        mysql_query($query);
    }elseif($group=='info'){
        $query="DELETE FROM `dt_information` WHERE group=$group";
        mysql_query($query);
        $query="INSERT INTO `dt_information` VALUES (NULL,'$group','$name','$content','$language_id')";
        mysql_query($query);
    }else{
        $query="INSERT INTO `dt_information` VALUES (NULL,'$group','$name','$content','$language_id')";
        mysql_query($query);
    }
}

function EditInformation($id,$name,$content,$language_id,$group){
    if($group=='home_page'){
        $query="DELETE FROM `dt_information` WHERE group=$group";
        mysql_query($query);
        $query="INSERT INTO `dt_information` VALUES (NULL,'$group','$name','$content','$language_id')";
        mysql_query($query);
    }elseif($group=='info'){
        $query="DELETE FROM `dt_information` WHERE group=$group";
        mysql_query($query);
        $query="INSERT INTO `dt_information` VALUES (NULL,'$group','$name','$content','$language_id')";
        mysql_query($query);
    }else{
        $query="UPDATE `dt_information` SET (`key`='$name',`value`='$content',`language_id`='$language_id',`group`='$group') WHERE informations_id=$id";
        mysql_query($query);
    }
}

function DeleteInformation($id){
    $query="DELETE FROM `dt_information` WHERE information_id=$id";
    mysql_query($query);
}

function InformationDetail($id){
    $query="SELECT * FROM `dt_information` WHERE information_id=$id";
    return mysql_query($query);
}

?>